<%@ page language="java" import="java.util.*,java.sql.*,connBean.*" pageEncoding="utf-8"%>
<%@page import="com.jspsmart.upload.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<jsp:useBean id="db" class="connBean.ConnDB" scope="page">
</jsp:useBean>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title></title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
<% 
  request.setCharacterEncoding("utf-8");
  SmartUpload upload =new SmartUpload();
  upload.initialize(pageContext);
  upload.setMaxFileSize(2000000000);
  upload.setAllowedFilesList("jpg,JPG,gif");
  upload.setDeniedFilesList("exe,bat,jsp,js,htm,html");
  upload.upload();
  upload.save("/images");
  
  int a_id=Integer.parseInt(upload.getRequest().getParameter("a_id"));
  String adminname=upload.getRequest().getParameter("a_name");
  String psw=upload.getRequest().getParameter("a_pass");
  String phone=upload.getRequest().getParameter("a_phone");
  String Email=upload.getRequest().getParameter("a_email");
  String filename=upload.getFiles().getFile(0).getFileName();
  String header=upload.getRequest().getParameter("header");
  System.out.println(filename);
  String sql="";
db.OpenConn();
PreparedStatement pstmt=null;



  if(filename.equals("") ||filename==null){
   sql="update admin set a_name=?,a_pass=?,a_phone=?,a_email=? where a_id="+a_id+"";
 pstmt=db.createPStmt(sql);
pstmt.setString(1,adminname);
pstmt.setString(2,psw);
pstmt.setString(3,phone);
pstmt.setString(4,Email);
   System.out.println(sql);}
   else{
   sql="update admin set a_name=?,a_pass=?,a_phone=?,a_email=?,a_header=? where a_id="+a_id+"";
 pstmt=db.createPStmt(sql);
pstmt.setString(1,adminname);
pstmt.setString(2,psw);
pstmt.setString(3,phone);
pstmt.setString(4,Email);
pstmt.setString(5,filename);
   System.out.println(sql);
   }
int result=pstmt.executeUpdate();

 if(result==1){ 
 response.sendRedirect("selectadmin.jsp");//执行插入成功跳转
 }else{
 %>
 修改失败，等待5秒后返回。
 <%
 response.setHeader("Refresh","5;URL=selectadmin.jsp");//执行插入失败跳转
 }
 db.closeConn();
%>  

  </body>
</html>